﻿//author: Sérgio Severino, nº 9733

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GUI_3._5
{
    public partial class Form1 : Form
    {

        private Database data;
        private string databaseName;
        private bool hasStatsMenu; // used on statistics menu

        public Form1(Database data, string databaseName)
        {
            this.data = data;
            this.databaseName = databaseName;
            bool hasStatsMenu = false;
            this.InitializeComponent();
            this.changeStatus("Waiting for action");
        }

        private void createDatabaseMenuItem_Click(object sender, EventArgs e)
        {
            this.changeStatus("Creating database... Please be patient...");
            Database.createDatabase("rebcsv", databaseName);
            this.changeStatus("Waiting for action");
        }

        private void exitMenuItem_Click(object sender, EventArgs e)
        {
            this.changeStatus("Shutting down");
            Dispose(true);
        }

        private void openDatabaseMenuItem_Click(object sender, EventArgs e)
        {
            if (File.Exists(Application.StartupPath + "/" +this.databaseName))
            {
                this.changeStatus("Opening database... Please be patient...");
                this.data.openDatabase(databaseName);
                if (!hasStatsMenu)
                {
                    this.addDatabaseMenu();
                    this.hasStatsMenu = true;
                }
                this.populateComboBoxes(this.data);
                this.changeStatus("Waiting for action");
            }
        }

        private void showTeacherpDpEpYpanel_evt(object sender, EventArgs e)
        {
            this.hideBasePanel();
            this.hideTeacherpEpYpanel();
            this.showTeacherpDpEpYpanel();
        }

        private void showTeacherpEpYpanel_evt(object sender, EventArgs e)
        {
            this.hideBasePanel();
            this.hideTeacherpDpEpYpanel();
            this.showTeacherpEpYpanel();
        }

        private void csvTpEpDpYButton1_Click(object sender, EventArgs e)
        {
            this.changeStatus("Generating file... Please be patient...");
            this.data.createCsvTpDpY(this.getCurrentInEs2(), this.getCurrentInDe2());
            this.changeStatus("Waiting for action");
        }

        private void listTpEpDpYButton2_Click(object sender, EventArgs e)
        {
            this.changeStatus("Generating file... Please be patient...");
            this.data.createListCsvTpDpY(this.getCurrentInEs2(), this.getCurrentInDe2());
            this.changeStatus("Waiting for action");
        }

        private void listTpEpYButton3_Click(object sender, EventArgs e)
        {
            this.changeStatus("Generating file... Please be patient...");
            this.data.createListCsvTpY(this.getCurrentInEs1());
            this.changeStatus("Waiting for action");
        }

        private void csvTpEpYBButton4_Click(object sender, EventArgs e)
        {
            this.changeStatus("Generating file... Please be patient...");
            this.data.createCsvTpY(this.getCurrentInEs1());
            this.changeStatus("Waiting for action");
        }
    }
}
